<!--
 * @message: 部门管理模块
-->
<template>
  <div class="dept">
    <Form inline :label-colon="true">
      <FormItem label="部门名称" :label-width="80">
        <Input v-model="params.deptName" placeholder="请输入部门名称"/>
      </FormItem>
      <FormItem>
        <Button
          type="primary"
          @click="publicGetData()"
          style="margin-right: 10px"
          v-auth="'列表'"
        >搜索</Button>
        <Button
        v-auth="'新增'"
         type="primary" @click="publicUpdateData()">新增</Button>
        <Button type="primary" style="margin-left: 10px;" @click="exportData"  v-auth="'导出'">导出</Button>
        <BaseImport
          v-auth="'导入'"
          :action="action.importDept"
          @onSuccess="handleSuccess"
          :templateName="templateName"
          :dowmTempName="uploadFileName">
        </BaseImport>
      </FormItem>
    </Form>
    <Breadcrumb></Breadcrumb>
    <BaseTable
      ref="baseTable"
      :action="action.readDeptByPage"
      :columns="columns"
      :menu-code="menuCode"
      :public-btn="['delete', 'update', 'view']"
       @handleView="publicUpdateData"
      @handleRemove="publicRemoveData"
      @handleUpdate="publicUpdateData"
    />
    <Drawer
      :title="viewParams.title"
      v-model="viewParams.flag"
      :width="35"
      draggable
      @on-visible-change="publicVisibleChange"
    >
      <DeptManageUpdate
        :type="type"
        @closeView="publicCloseView"
        :key="isRefreshView"
        :topUnitList="unitList"
        :idName="idName"
        :moduleId="id"/>
    </Drawer>
  </div>
</template>

<script>
import { tableMixin } from '../../../mixin'
import API_KEY from '../../../api'
import columns from './dept-columns'
import { getUnitSelect } from '../../../api/modules/user/unit'
import { exportDept } from '../../../api/modules/user/dept'
import message from '../../../utils/message'
import BaseUtil from '../../../utils/BaseUtil'

export default {
  name: 'DeptManage',
  mixins: [tableMixin],
  data () {
    return {
      params: {
        deptName: ''
      },
      action: {
        readDeptByPage: API_KEY.dept.readDeptByPage,
        removeDataByKey: API_KEY.dept.deleteDeptByKey,
        importDept: API_KEY.dept.importDept
      },
      columns,
      idName: 'id',
      id: '',
      unitList: [],
      menuCode: 'account-dept',
      templateName: 'AccountDept.xlsx',
      downTempName: '单位信息.xlsx',
      uploadFileName: '部门信息模板.xlsx',
      suffix: '部门信息'
    }
  },
  mounted () {
    /**
     * 获取菜单下拉
     */
    getUnitSelect().then(res => {
      this.unitList = res.data
    })
  },
  methods: {
    /**
     * 部门管理记录导出
     */
    exportData () {
      exportDept(this.params).then(res => {
        message.message.success(res.message)
        BaseUtil.downFile(res.data, this.downTempName)
      })
    },
    /**
     * 导入
     */
    handleSuccess (val) {
      this.$refs.baseTable.getData()
    }
  },
  components: {
    DeptManageUpdate: () => import('./DeptManageUpdate'),
    BaseImport: () => import('../../../components/view-ui/BaseImport')
  }
}
</script>

<style scoped>

</style>
